#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
struct box {
	double Red;
	double green;
};
int cmp_Red(const void* p1, const void* p2) {
	return ((struct box*)p1)->Red - ((struct box*)p2)->Red;
}
int cmp_green(const void* p1, const void* p2) {
	return ((struct box*)p1)->green - ((struct box*)p2)->green;
}
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	double count = 0;
	struct box arr[] = { 0 };
	for (int i = 0; i < n; i++) {
		scanf("%lf %lf", &arr[i].Red, &arr[i].green);
	}
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_green);
	for (int i = 0; i < k; i++) {
		count += (double)arr[sz - i - 1].green;
		arr[sz - i - 1].Red = 0;
	}
	qsort(arr, sz, sizeof(arr[0]), cmp_Red);
	for (int i = 0; i < n - k; i++) {
		count += arr[sz - i - 1].Red;
	}
	printf("%lf", count);

	return 0;
}